// 合同文件
<template>
  <div>
    <div class="padding-bottom-10 flex justify-between">
      <span class="font-weight-700 font-size-18">合同文件</span>
    </div>
    <el-table :border="false" :data="tableList" class="new-table-style">
      <el-table-column align="left" label="签署时间" prop="workNum" width="160">
        <template slot-scope="scope">
          <span>{{ scope.row.contractCreateDate | formatDateTime('YYYY-MM-DD') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="合同类型" width="200">
        <template slot-scope="scope">
          <span>{{ scope.row.classification == 'supplement' ? '补充协议' : (scope.row.classification == 'returnRent' ? '退租协议' : '主合同') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="合同名称" prop="contractName"> </el-table-column>
      <el-table-column label="操作" align="center" width="260">
        <template slot-scope="scope">
          <el-button type="text" @click="seaFile(scope.row)">查看合同文件</el-button>
          <el-button type="text" @click="seaApproveInfo(scope.row)" class="padding-left-20">查看审批信息</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="合同文件" :visible.sync="fileDialogShow" width="65%" :close-on-click-modal="false" :close-on-press-escape="false">
      <div class="padding-bottom-10 font-size-16">合同名称：{{ currentObj.contractName }}</div>
      <div v-if="fileList.length > 0">
        <el-link v-for="file in fileList" :key="file.primaryKey" type="primary" class="padding-right-15" @click="downFile(file.fileUrl)">{{ file.fileTitle }}</el-link>
      </div>
      <div v-else>暂无附件</div>
    </el-dialog>

    <el-dialog title="审批信息" :visible.sync="approveDialogShow" width="85%" :close-on-click-modal="false" :close-on-press-escape="false">
      <approve-info ref="approve" :workId="currentObj.workId" :showTitle="false" :newTableStyle="true"></approve-info>
    </el-dialog>
  </div>
</template>

<script>
  import approveInfo from '@/common/components/approveInfo';
  import { apiBusinessContractAttachment } from '../../../../api/contract';
  import { uploadLoad } from '@/common/js/utils';

  export default {
    props: {
      tableList: {
        type: Array,
        default: () => {
          return [];
        },
      },
    },

    data() {
      return {
        fileDialogShow: false,
        approveDialogShow: false,
        fileList: [],
        currentObj: {},
      };
    },

    mounted() {},

    methods: {
      seaFile(row) {
        this.currentObj = row;
        this.getBusinessContractAttachment();
        this.fileDialogShow = true;
      },
      seaApproveInfo(row) {
        this.currentObj = row;
        this.approveDialogShow = true;
        this.$nextTick(() => [this.$refs.approve.getInfo()]);
      },
      async getBusinessContractAttachment() {
        let res = await apiBusinessContractAttachment({
          bizId: this.currentObj.primaryKey,
          notInBizTypeList: ['billImport']
        });
        this.fileList = res.rows || [];
        console.log(this.fileList);
      },
      //下载附件
      downFile(url) {
        if(url && url.indexOf('jhzl') > -1 && !(url.indexOf('.docx') > -1  || url.indexOf('.xlsx') > -1 || url.indexOf('.doc') > -1)){
          window.open(url, '_blank')
          return
        }
        uploadLoad(url);
      },
    },

    components: { approveInfo },
  };
</script>

<style lang="scss" scoped></style>
